package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.hfq.UploadBaseData;
import com.ucredit.babel.common.model.hfq.phoneinfo.UploadPhoneInfoData;
import com.ucredit.babel.common.model.hfq.phoneinfo.UploadPhoneInfoRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Classname HfgPhoneDeviceInfo
 * @Description 用户采集信息数据字段结构化-设备信息&GPS
 * @Date 2021/6/8 19:42
 * HFQ_UPLOAD_PHONE_INFO_RECORD* @Created by lzw
 */
public class HfgPhoneDeviceInfo extends ParseBase {
    Text key = new Text();
    Text value = new Text();

    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        UploadPhoneInfoRecord obj = (UploadPhoneInfoRecord) model;
        UploadPhoneInfoData data = obj.getData();
        UploadBaseData baseData = data.getBaseData();

        StringBuilder sb = getBaseInfo(obj, successful);

        sb.append(formatValue(baseData.getHttpTimestamp())).append(CRT001);
        sb.append(formatValue(baseData.getUploadInfoOpportunity())).append(CRT001);
        sb.append(formatValue(obj.getType())).append(CRT001);

        sb.append(formatValue(data.isSimulator())).append(CRT001);
        sb.append(formatValue(data.isAllowMockLocation())).append(CRT001);
        sb.append(formatValue(data.getAndroidId())).append(CRT001);
        sb.append(formatValue(data.getBlueMac())).append(CRT001);
        sb.append(formatValue(data.getImei())).append(CRT001);
        sb.append(formatValue(data.getImsi())).append(CRT001);
        sb.append(formatValue(data.getModel())).append(CRT001);
        sb.append(formatValue(data.getPhoneNumber())).append(CRT001);
        sb.append(formatValue(data.isRoot())).append(CRT001);
        sb.append(formatValue(data.getScreenRes())).append(CRT001);
        sb.append(formatValue(data.getSerialNo())).append(CRT001);
        sb.append(formatValue(data.getSimOperator())).append(CRT001);
        sb.append(formatValue(data.getWifiMac())).append(CRT001);
        sb.append(formatValue(data.getBrand())).append(CRT001);
        sb.append(formatValue(data.getBatteryStatus())).append(CRT001);
        sb.append(formatValue(data.getBssid())).append(CRT001);
        sb.append(formatValue(data.getCarrier())).append(CRT001);
        sb.append(formatValue(data.getCellIp())).append(CRT001);
        sb.append(formatValue(data.getCurrentTime())).append(CRT001);
        sb.append(formatValue(data.getDeviceId())).append(CRT001);
        sb.append(formatValue(data.getDeviceName())).append(CRT001);
        sb.append(formatValue(data.getKernelVersion())).append(CRT001);
        sb.append(formatValue(data.getLanguage())).append(CRT001);
        sb.append(formatValue(data.getNetworkType())).append(CRT001);
        sb.append(formatValue(data.getOs())).append(CRT001);
        sb.append(formatValue(data.getSsid())).append(CRT001);
        sb.append(formatValue(data.getTimeZone())).append(CRT001);
        sb.append(formatValue(data.getTotalMemory())).append(CRT001);
        sb.append(formatValue(data.getTotalStorage())).append(CRT001);
        sb.append(formatValue(data.getUpTime())).append(CRT001);
        sb.append(formatValue(data.getWifiIp())).append(CRT001);
        sb.append(formatValue(data.getWifiNetmask())).append(CRT001);
        sb.append(formatValue(data.getOsVersion())).append(CRT001);
        sb.append(formatValue(data.getIdfa())).append(CRT001);
        sb.append(formatValue(data.getIdfv())).append(CRT001);
        sb.append(formatValue(data.isJailbreak())).append(CRT001);
        sb.append(formatValue(data.getPlatform())).append(CRT001);
        sb.append(formatValue(data.getUuid())).append(CRT001);
        sb.append(data.getWifiIPProvince() == null ? "" : formatValue(data.getWifiIPProvince())).append(CRT001);
        sb.append(data.getWifiIPCity() == null ? "" : formatValue(data.getWifiIPCity())).append(CRT001);
        sb.append(data.getCellIPProvince() == null ? "" : formatValue(data.getCellIPProvince())).append(CRT001);
        sb.append(data.getCellIPCity() == null ? "" : formatValue(data.getCellIPCity())).append(CRT001);
        sb.append(formatValue(data.getAdMac())).append(CRT001);
        sb.append(formatValue(data.getForwardedfor())).append(CRT001);
        sb.append(formatValue(data.getRemoteAddr())).append(CRT001);
        sb.append(formatValue(data.getScreenBright())).append(CRT001);
        sb.append(formatValue(data.getFreeStorage())).append(CRT001);
        sb.append(formatValue(data.getChannel())).append(CRT001);
        sb.append(formatValue(data.getOriginData())).append(CRT001);
        setFileNum(10);
        key.set(getKey());
        value.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, value);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_hfq_phone_info_inc";
    }

    @Override
    public String getType() {
        return RecordType.HFQ_UPLOAD_PHONE_INFO_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "设备信息";
    }
    
}
